package com.ekingstar.framework.domain;

import org.springframework.security.GrantedAuthority;
import org.springframework.security.userdetails.UserDetails;

/**
 * User entity. @author MyEclipse Persistence Tools
 */
public class User extends AbstractUser implements java.io.Serializable,UserDetails {

	// Constructors

	public static enum Type{
		SYSTEM{
			public String toString(){
				return "系统账户";
			}	
		},
		EDU{
			public String toString(){
				return "教委账户";
			}	
		},
		University_PT{
			public String toString(){
				return "普通高校账户";
			}
		},
		University_CR{
			public String toString(){
				return "成人高校账户";
			}
		},
		University_YJS{
			public String toString(){
				return "研究生高校账户";
			}
		},
		University_WLJY{
			public String toString(){
				return "网络教育高校账户";
			}
		},
		Student{
			public String toString(){
				return "学生账户";
			}
		}
		
	};
	
	public String getUserTypeName(){
		if (this.getUserType() != null){
			return Type.valueOf(this.getUserType()).toString();
		}
		return "";
	}
	private Boolean canUse;
	private Boolean canGrant;
	private Person userInfo = new Person();
	public Person getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(Person userInfo) {
		this.userInfo = userInfo;
	}

	public Boolean getCanUse() {
		return canUse;
	}

	public void setCanUse(Boolean canUse) {
		this.canUse = canUse;
	}

	public Boolean getCanGrant() {
		return canGrant;
	}

	public void setCanGrant(Boolean canGrant) {
		this.canGrant = canGrant;
	}

	/** default constructor */
	public User() {
	}

	private GrantedAuthority[] authorities;

	public void setAuthorities(GrantedAuthority[] authorities) {
		this.authorities = authorities;
	}

	/** minimal constructor */
	public User(String id) {
		super(id);
	}

	

	public GrantedAuthority[] getAuthorities() {
		// TODO Auto-generated method stub
		return authorities;
	}

	public String getPassword() {
		// TODO Auto-generated method stub
		return this==null?null:this.getPwd();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.userdetails.UserDetails#getUsername()
	 */
	public String getUsername() {
		// TODO Auto-generated method stub
		return this==null?null:this.getName();
	}

	public boolean isAccountNonExpired() {
		Boolean expired = this.getExipred();
		if (expired == null) return false;
		return !expired.booleanValue();
		// TODO Auto-generated method stub
	}

	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		Boolean locked = this.getLocked();
		if (locked == null) return false;
		return !locked.booleanValue();
	}

	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		if (this.getPasswordexipred() != null && this.getPasswordexipred().booleanValue()==true){
			return false;
		}
		
		return true;
	}

	public boolean isEnabled() {
		Boolean enabled = super.getEnabled();
		if (enabled == null) return true;
		return enabled.booleanValue();
	}
	public void setEnabled(boolean enabled){
		super.setEnabled(enabled);
	}

}
